package com.xiaoxu.scala_base.code

/**
  *
  * author: zhangXu
  * createTime: 2018-12-09 16:09
  **/
object Constructor {

  def main(args: Array[String]): Unit = {
    new Student("name",18,"hobby")
  }

}

//主构造器
class People1(var name: String, val age: Int) {
  println("People1  enter....")

  var sex: String = "男"

  val height: Int = 180;

  //附属构造器
  def this(name: String, age: Int,sex: String) {
    //调用主构造器
    //附属构造器，第一行代码必须调用主构造器，或者其他附属构造器
    this(name, age)
    this.sex = sex
  }

  def read(): Unit ={
    println("read")
  }

  println("People1  leave....")
}

class Student(name:String, age:Int, var hobby:String) extends People1(name, age) {
  println("People1 Student enter....")


  override val height = 185

  override def toString: String = "People1: override def toString :"

  override def read(): Unit ={
      println("override read")
  }

  println("People1 Student leave....")
}
